﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using Convertor.Interface;
using Wpf.CommonTools;
using Wpf.CommonTools.SystemExtension;

namespace Convertor
{
    class AllPluginToNamesConverter : IMultiValueConverter
    {
        #region IMultiValueConverter 成员

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var allPlugin = values[0] as ObservableDictionary<string, object>;
            ObservableCollection<string> disablePluginList = (values[2] as ObservableCollection<string>) ?? new ObservableCollection<string>();
            if (allPlugin != null)
            {
                string type = (values[1] ?? string.Empty).ToString().Replace(UILanguage.FindResource("All"), string.Empty);
                var names = allPlugin.Select(p => new PluginItem(p.Key, p.Value)).OrderBy(p => p.Name)
                    .Where(p => p.Name.StartsWith(type))
                    .Where(p => !disablePluginList.Contains(p.Path))
                    .OrderBy(p => p.Name).ToArray();
                return names;
            }
            else
            {
                return null;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
